package top.ewind.interceptor.mqtt;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
/**
 * @author wangchao
 *
 */
public abstract class AbstractMsgStrategy{

	public String decodeToStr(ByteBuffer buff){
		Charset charset = Charset.forName("UTF-8");;
        CharsetDecoder decoder = charset.newDecoder();
		try {
        	CharBuffer charBuffer = decoder.decode(buff);
			String strmsg = charBuffer.toString().replaceAll("\\s", "");
			return strmsg;
		} catch (Exception e) {
			return "";
		}
	}

}
